/*
 * @Author: LBH 1336709799@qq.com
 * @Date: 2024-10-29 12:00:10
 * @LastEditors: LBH 1336709799@qq.com
 * @LastEditTime: 2024-10-29 12:09:51
 * @FilePath: \enjoy_plus_three\lib\pages\notice\index.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:enjoy_plus_three/utils/http.dart';
import 'package:enjoy_plus_three/utils/toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

class NoticeDetail extends StatefulWidget {
  const NoticeDetail({super.key});

  @override
  State<NoticeDetail> createState() => _NoticeDetailState();
}

class _NoticeDetailState extends State<NoticeDetail> {

  Map notifyDetail = {};

  Map<String, dynamic> params = {};
  @override
  void didChangeDependencies() {
  super.didChangeDependencies();
  final data = ModalRoute.of(context)?.settings.arguments;
  if (data != null) {
    params = data as Map<String, dynamic>;
    getNotifyDetail();
  }
 }

 getNotifyDetail() async{
  final res = await http.get('/announcement/${params['id']}');
  if(res['code'] != 10000) return ToastUtil.showError('公告详情获取失败');
  setState(() {
    notifyDetail = res['data'];
  });
 }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('公告详情'),
      ),
      body: ListView(
        children: [
          Container(
            padding: const EdgeInsets.all(10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 标题
                Text(
                  // flutter
                  // ??条件访问运算符 称为null合并运算符
                  // a ?? b
                  // 只有a为null 才会执行b
                  notifyDetail['title']?? '',
                  style: const TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  )
                ),
                const SizedBox(height: 10),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      notifyDetail['creatorName']?? '',
                      style: const TextStyle(
                        color: Colors.grey
                      )
                    ),
                    Text(
                      notifyDetail['createdAt']?? '',
                      style: const TextStyle(
                        color: Colors.grey
                      )
                    )
                  ]
                ),
                const SizedBox(height: 10),
                // 内容
                Html(
                  data: notifyDetail['content']?? '',
                )
              ]
            )
          )
        ]
      )
    );
  }
}